<template>
  <div>
    <van-nav-bar
  title="账号登录"
  left-arrow
  @click-left="onClickLeft"
/>
<van-form @submit="onSubmit">
  <van-field
    v-model="formLogin.username"
    name="账号"
    placeholder="请输入账号"
    :rules="[{ required: true, message: '请填写用户名' }]"
  />
  <van-field
    v-model="formLogin.password"
    type="password"
    name="密码"
    placeholder="请输入密码"
    :rules="[{ required: true, message: '请填写密码' }]"
  />
  <div style="margin: 16px;">
    <van-button block color="#58b67f" :loading="isLoading" :disabled="isLoading" size="large"  type="info" native-type="submit">登 录</van-button>
  </div>
</van-form>
    <p class="text">还没有账号，去注册～</p>
  </div>
</template>

<script>
import { Toast, Notify } from 'vant'
import { mapActions } from 'vuex'
export default {
  name: 'Login',
  data () {
    return {
      formLogin: {
        username: 'hzhmqd',
        password: '123456'
      },
      isLoading: false
    }
  },
  methods: {
    ...mapActions(['asyncLoginAction']),
    onClickLeft () {
      Toast('返回')
    },
    async onSubmit (values) {
      this.isLoading = true
      try {
        this.isLoading = false
        this.asyncLoginAction(this.formLogin)
        Notify({ type: 'success', message: '登录成功' })
        this.$router.replace({
          path: '/layout/profile'
        })
      } catch (err) {
        Notify({ type: 'warning', message: '手机号或密码错误' })
        this.isLoading = false
        console.log(err)
      }
    }

  }
}
</script>

<style lang="less" scoped>
// .van-nav-bar {
//   background-color: #58b67f;
// }
.van-cell {
  line-height: 1rem;
  // padding-top: 0.3rem;
}
.van-button {
  font-size: 0.5rem;
}
.text {
  color: #666;
  font-size: 0.35rem;
  text-align: center;
  margin-top: .875rem;
}
</style>
